package com.topfinance.cnaps2.web.sys;

import java.util.HashMap;
import java.util.List;

import com.topfinance.cnaps2.service.IMsgMatchManager;
import com.topfinance.frame.web.BaseSupport;

/**
 * <p>
 * Description:
 * </p>
 * 
 * @author
 * @version 1.50
 *          <p>
 *          Copyright: Copyright (c) 2004 2005
 *          </p>
 *          <p>
 *          Company:
 *          </p>
 */
public final class MsgMatchAction extends BaseSupport{

	private IMsgMatchManager msgMatchManager = null;

	public void setMsgMatchManager(IMsgMatchManager msgMatchManager) {
		this.msgMatchManager = msgMatchManager;
	}

	public MsgMatchAction() {
		super();
	}

	public String execute() {
		return listallmatch();
		//return SUCCESS;
	}
	
	public String listmsgmatch() {
		log.debug("MsgMatchAction-list begin");
		try {
			String type = request.getParameter("type");
			String msg = request.getParameter("msg");
			String dir = request.getParameter("dir");
			List match = msgMatchManager.getMsgMatchList(type, msg, dir);
			rtnResultMap = new HashMap();
			rtnResultMap.put(DATA_LIST_ROOT, match);
			rtnResultMap.put(RECORDS_COUNT, match.size());			
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("MsgMatchAction-list end");
		return SUCCESS;
	}

	public String listallmatch() {
		log.debug("MsgMatchAction-list begin");
		try {
			List match = msgMatchManager.getMsgMatchListAll();
			rtnResultMap = new HashMap();
			rtnResultMap.put(DATA_LIST_ROOT, match);
			rtnResultMap.put(RECORDS_COUNT, match.size());			
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("MsgMatchAction-list end");
		return SUCCESS;
	}

	public String listcurmsg() {
		long bgn = System.currentTimeMillis();
		log.debug("MsgMatchAction-listcurmsg begin");
		try {
			String curday = request.getParameter("curday");
			String lststamp = request.getParameter("lststamp");
			if(lststamp !=null)
				log.debug("[获得最新消息]" + lststamp);
			List match = msgMatchManager.getCurMsgList(curday,lststamp);
			rtnResultMap = new HashMap();
			rtnResultMap.put(DATA_LIST_ROOT, match);
			rtnResultMap.put(RECORDS_COUNT, match.size());
		} catch (Exception e) {
			handleException(e);
		}
		long end = System.currentTimeMillis();
		log.debug("MsgMatchAction-listcurmsg exetime(million):" + (end-bgn));
		return SUCCESS;
	}

	public String listmsgline() {
		long bgn = System.currentTimeMillis();
		log.debug("MsgMatchAction-listmsgline begin");
		try {
			String txid = request.getParameter("txid");	
			List msgLine = msgMatchManager.getMsgLine(txid);
			rtnResultMap = new HashMap();
			rtnResultMap.put(DATA_LIST_ROOT, msgLine);
			rtnResultMap.put(RECORDS_COUNT, msgLine.size());
		} catch (Exception e) {
			handleException(e);
		}
		long end = System.currentTimeMillis();
		log.debug("MsgMatchAction-listmsgline exetime(million):" + (end-bgn));
		return SUCCESS;
	}
	
}
